Skip to content

fix JitCall codegen for function with lambda as return value #678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2025

Conversation

Vipul-Cariappa
Copy link
Collaborator

Description

Fixes # (issue)

Helps fix a test in cppyy

Type of change

Please tick all options which are relevant.

  • Bug fix
  • New feature
  • Requires documentation updates

Testing

Checklist

  • I have read the contribution guide recently

Copy link

codecov bot commented Jul 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.74%. Comparing base (41f26a3) to head (334b41d).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #678      +/-   ##
==========================================
+ Coverage   79.68%   79.74%   +0.06%     
==========================================
  Files           9        9              
  Lines        3942     3955      +13     
==========================================
+ Hits         3141     3154      +13     
  Misses        801      801              
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOp.cpp 87.87% <100.00%> (+0.07%) ⬆️
Files with missing lines Coverage Δ
lib/CppInterOp/CppInterOp.cpp 87.87% <100.00%> (+0.07%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

bool IsLambdaClass(TCppType_t type) {
QualType QT = QualType::getFromOpaquePtr(type);
if (auto* CXXRD = QT->getAsCXXRecordDecl()) {
return CXXRD->isLambda();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI isLambdaCallOperator in clang.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isLambdaCallOperator takes a CXXMethodDecl, but we are using QualType to check here.
Also, we are not checking if the function is the lambda call operator; instead, we are checking if the given class is a lambda class.

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@Vipul-Cariappa
Copy link
Collaborator Author

Hi @anutosh491, @mcbarton,
Could you please look at this. Why is this failing on Emscripten?
The only Emscripten relevant change is the I->declare(...) in Cpp::CreateInterpreter.

@anutosh491
Copy link
Collaborator

anutosh491 commented Jul 30, 2025

Weird ..... it says the exception handling test fails. I can recreate the exact same example in the lite deployment

TEST(InterpreterTest, EmscriptenExceptionHandling) {
#ifndef EMSCRIPTEN
GTEST_SKIP() << "This test is intended to check exception handling for Emscripten builds.";
#endif
std::vector<const char*> Args = {
"-std=c++20",
"-v",
"-fexceptions",
"-fcxx-exceptions",
"-mllvm", "-enable-emscripten-cxx-exceptions",
"-mllvm", "-enable-emscripten-sjlj"
};
Cpp::CreateInterpreter(Args);
const char* tryCatchCode = R"(
try {
throw 1;
} catch (...) {
0;
}
)";
EXPECT_TRUE(Cpp::Process(tryCatchCode) == 0);

image

@mcbarton
Copy link
Collaborator

Weird ..... it says the exception handling test fails. I can recreate the exact same example in the lite deployment

TEST(InterpreterTest, EmscriptenExceptionHandling) {
#ifndef EMSCRIPTEN
GTEST_SKIP() << "This test is intended to check exception handling for Emscripten builds.";
#endif
std::vector<const char*> Args = {
"-std=c++20",
"-v",
"-fexceptions",
"-fcxx-exceptions",
"-mllvm", "-enable-emscripten-cxx-exceptions",
"-mllvm", "-enable-emscripten-sjlj"
};
Cpp::CreateInterpreter(Args);
const char* tryCatchCode = R"(
try {
throw 1;
} catch (...) {
0;
}
)";
EXPECT_TRUE(Cpp::Process(tryCatchCode) == 0);

image

@anutosh491 could this have anything to do with the fact that exception handling in CppInterOps deployment doesn't currently work (I'm assuming your example comes from xeus-cpps deployment)? That requires this PR to go in #686 (patch taken from Emscripten forge).

@anutosh491
Copy link
Collaborator

No it shouldn't matter (unless anything in createinterpreter or process changed)

@vgvassilev
Copy link
Contributor

Hi @anutosh491, @mcbarton, Could you please look at this. Why is this failing on Emscripten? The only Emscripten relevant change is the I->declare(...) in Cpp::CreateInterpreter.

I think this can be ifdef-ed if it's too hard to fix for emscripten...

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@mcbarton
Copy link
Collaborator

mcbarton commented Jul 31, 2025

@vgvassilev @Vipul-Cariappa if you look at this job https://github.com/compiler-research/CppInterOp/actions/runs/16648661110/job/47122629847?pr=678 it passes the test other Emscripten jobs fail for. The only difference between this job and the other llvm 20 Emscripten jobs is that this patch has been applied on main https://github.com/compiler-research/CppInterOp/blob/main/patches/llvm/emscripten-clang20-3-enable_exception_handling.patch . I hadn't updated all the llvm 20 caches yet, since it quite disruptive and I planned to do it this evening when things are quiet. Once I have updated the llvm 20 Emscripten cache on main, then all the llvm 20 jobs should then pass. To get all the jobs to pass you would need to backport this patch to llvm 19.

Copy link
Contributor

github-actions bot commented Aug 1, 2025

clang-tidy review says "All clean, LGTM! 👍"

@mcbarton
Copy link
Collaborator

mcbarton commented Aug 1, 2025

@Vipul-Cariappa @vgvassilev The llvm 19 Emscripten jobs are now passing the test they were previously failing for, now the exception handling patch has been backported. The ci should hopefully pass now.

Copy link
Contributor

github-actions bot commented Aug 2, 2025

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

github-actions bot commented Aug 7, 2025

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

github-actions bot commented Aug 7, 2025

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

github-actions bot commented Aug 8, 2025

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mcbarton mcbarton merged commit dba60ff into compiler-research:main Aug 9, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants